<template>
  <div>
    <!-- 头部搜索部分 -->
    <div class="top-one-content">
      <div class="contentBox"><span class="logo">发布平台</span></div>
      <div class="contentBox">
        <el-select v-model="query.client" placeholder="请选择" size="mini">
          <el-option
            v-for="(item, index) in options"
            :key="index"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </div>
      <div class="contentBox">
        <el-button size="mini" icon="el-icon-search" @click="sou"
          >搜索</el-button
        ><el-button size="mini" icon="el-icon-edit" @click="del"
          >重置</el-button
        >
      </div>
    </div>
    <!-- 新建按钮部分 -->
    <div class="top-tow-content">
      <el-button type="primary" size="mini" @click="goto(1)"
        >新建PC端banner</el-button
      >
      <el-button type="primary" size="mini" @click="goto(2)"
        >新建移动端banner</el-button
      >
    </div>
    <!-- 中间表格部分 -->
    <div class="top-table-content">
      <el-table
        :data="tableData.list"
        style="width: 100%"
        :stripe="true"
        :border="true"
        v-loading="loading"
      >
        <el-table-column
          prop="date"
          label="banner图"
          width="180"
          align="center"
        >
          <template slot-scope="scope">
            <img :src="scope.row.banner_img" alt="" class="bannerImg" />
          </template>
        </el-table-column>
        <el-table-column prop="name" label="链接" width="180" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.link_content_name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="发布平台" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.client_type | BannerclientType }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="faburen" label="发布人" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.create_user }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="addtime" label="创建时间" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.created_at | formatDate }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="xuhao" label="序号" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.sort }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="caozuo" label="操作" align="center">
          <template slot-scope="scope">
            <el-link type="primary">编辑</el-link>-
            <el-link type="primary" @click="delet(scope.row.id)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 底部分页器部分 -->
    <div class="block">
      <el-pagination
        @size-change="statusChage"
        @current-change="currentChange"
        :page-sizes="[3, 6, 9, 12]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { getBannerList } from '../../../api/api3'

export default {
  data() {
    return {
      // 这是loading
      loading: false,
      options: [
        {
          value: '1',
          label: 'PC'
        },
        {
          value: '2',
          label: '安卓'
        },
        {
          value: '3',
          label: 'iOS'
        },
        {
          value: '4',
          label: 'H5'
        },
        {
          value: '5',
          label: '小程序'
        }
      ],
      value: '',
      total: 1,
      tableData: [],
      query: {
        page: 1,
        limit: 3,
        client: ''
      }
    }
  },
  methods: {
    // 跳转路由
    goto(status) {
      this.$router.push({
        name: 'OperationBannerStatus',
        query: { platform: status }
      })
    },
    // 分页器部分
    statusChage(page) {
      console.log(page)
      this.query.limit = page
      this.statusList()
    },
    currentChange(page) {
      console.log(page)
      this.query.page = page
      this.statusList()
    },
    // 点击搜索发生变化
    sou() {
      console.log(this.query.client)

      this.statusList()
    },
    del() {
      this.query.client = ''
      this.statusList()
    },
    // 删除功能
    delet(id) {
      axios
        .delete('/banner/' + id)
        .then((res) => {
          this.statusList()
        })
        .finally(() => {
          this.loading = true
        })
    },
    // 更改时发生变化
    statusList() {
      getBannerList(this.query).then((res) => {
        console.log(res)
        this.tableData = res.data
        this.total = res.data.total
        this.loading = false
      })
    }
  },
  mounted() {
    this.statusList()
  },
  filters: {
    BannerclientType: function (text) {
      const a = text.replace('1', 'PC')
      const b = a.replace('2', '安卓')
      const c = b.replace('3', 'iOS')

      const d = c.replace('5', '小程序')
      const e = d.replace('4', 'H5')
      return e
    }
  }
}
</script>
<style lang="scss">
.top-one-content {
  height: 40px;
  display: inline-flex;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 20px;
  .contentBox {
    margin-right: 10px;
  }
}
.top-tow-content {
  margin-bottom: 20px;
}
.block {
  float: right;
}
//elementui全局配置
.el-table td,
.el-table th {
  padding: 5px 0px !important;
}
//个别小改动
.logo {
  font-size: 12px;
}
.bannerImg {
  width: 70px;
  height: 36px;
  vertical-align: middle;
}
</style>
